package main

import (
	"fmt"
	"time"
)

type ReqI interface {
	Handler(url string) string
}

type Req struct {
}

func (r *Req) Handler(url string) string {
	fmt.Println("请求", url)
	return ""
}

type LogReqDecorator struct {
	R ReqI
}

func (l *LogReqDecorator) Handler(url string) string {
	fmt.Println("日志记录前")
	l.R.Handler(url)
	fmt.Println("日志记录后")
	return ""
}

type MonitorDecorator struct {
	R ReqI
}

func (m *MonitorDecorator) Handler(url string) string {
	t1 := time.Now()
	m.R.Handler(url)
	sub := time.Since(t1)
	fmt.Println("请求耗时:", sub)
	return ""
}

func main() {
	req := &MonitorDecorator{&LogReqDecorator{&Req{}}}
	req.Handler("http://www.baidu.com")
}
